﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace TestePI2
{
    public partial class frmCadastro : Form
    {
        public frmCadastro()
        {
            InitializeComponent();

        }

        private void btnInserirImagem_Click(object sender, EventArgs e)
        {

        }
        public string artista;

        private void Cadastro_Load(object sender, EventArgs e)
        {
                try
                {
                    SqlConnection conn = new SqlConnection("Data Source=EMERSON-PC\\SQLEXPRESS;Initial Catalog=PROJETO_MUSICA;Integrated Security=True");
                    conn.Open();

                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter("SELECT ID_ARTISTA, NM_ARTISTA FROM TB_ARTISTA ORDER BY NM_ARTISTA",conn);
                da.Fill(dt);
                cmbCadastraArtista.DisplayMember = "NM_ARTISTA";
                cmbCadastraArtista.ValueMember = "ID_ARTISTA";
                cmbCadastraArtista.DataSource = dt;                
                
                conn.Close();

                }
                catch(SqlException sqlExp)
                {
                    MessageBox.Show(sqlExp.Message);
                }
                
                
               
      //  }
    }

        private void cmbCadastraArtista_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn = new SqlConnection("Data Source=EMERSON-PC\\SQLEXPRESS;Initial Catalog=PROJETO_MUSICA;Integrated Security=True");
                conn.Open();

                cmbCadastraArtista.ValueMember = "ID_ARTISTA";
                
                DataTable album = new DataTable();
                SqlDataAdapter adap = new SqlDataAdapter("SELECT NM_ALBUM FROM TB_ARTISTA_ALBUM    A INNER JOIN TB_ALBUM B ON A.ID_ALBUM = B.ID_ALBUM WHERE ID_ARTISTA = " + cmbCadastraArtista.ValueMember, conn);
                adap.Fill(album);
                cmbAlbum.DisplayMember = "NM_ALBUM";
                //cmbAlbum.ValueMember = "NM_ALBUM";
                cmbAlbum.DataSource = album;

                conn.Close();

            }
            catch (SqlException sqlExp)
            {
                MessageBox.Show(sqlExp.Message);
            }
               

        }
    }
}